package com.hu.create;

import java.util.concurrent.*;

/**
 * @author 00355760
 * @功能：
 * @版本： V1
 * @版权： 信息技术有限公司（http://www.mychery.com/）
 * @作者： 磐石战队开发组  00355760
 * @日期： 2024/9/19 14:18
 */
public class CallableTest implements Callable<Boolean> {
    @Override
    public Boolean call() throws Exception {
        DownLoader downLoader = new DownLoader();
        downLoader.download(url, name);
        System.out.println(Thread.currentThread().getName() + "下载了" + name);
        return true;
    }
    private String name;
    private String url;

    public CallableTest(String name, String url) {
        this.name = name;
        this.url = url;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableTest callableTest1 = new CallableTest("1.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        CallableTest callableTest2 = new CallableTest("2.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        CallableTest callableTest3 = new CallableTest("3.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        //创建执行服务
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        //提交执行
        Future<Boolean> submit1 = executorService.submit(callableTest1);
        Future<Boolean> submit2 = executorService.submit(callableTest2);
        Future<Boolean> submit3 = executorService.submit(callableTest3);
        //获取结果
        System.out.println(submit1.get());
        System.out.println(submit2.get());
        System.out.println(submit3.get());
        //关闭服务
        executorService.shutdown();
    }
}
